import request from '@/utils/request'

/**
 * 终端配置初始化
 */
export function terminalAdminInit() {
  return request({
    url: '/terminal/equipment/display',
    method: 'GET'
  })
}

/**
 * 终端配置分页
 * @param {Number} page 分页页码
 */
export function terminalAdminPage(page) {
  return request({
    url: '/terminal/equipment/display',
    method: 'GET',
    params: { page }
  })
}

/**
 * 终端配置查看终端详情
 * @param {Number} define_id 终端id
 */
export function adminTerminalList(define_id) {
  return request({
    url: '/terminal/equipment/detail',
    method: 'GET',
    params: { define_id }
  })
}

/**
 * 终端配置查看终端删除
 * @param {Number} define_id 终端id
 */
export function adminTerminalDelete(define_id) {
  return request({
    url: '/terminal/equipment/delete',
    method: 'DELETE',
    params: { define_id }
  })
}

/**
 * 终端类别配置初始化
 */
export function TerminalConfigInit() {
  return request({
    url: 'terminal/terminal/category',
    method: 'GET'
  })
}

/**
 * 终端sn初始化
 */
export function TerminalConfigSnInit(agent_id) {
  return request({
    url: 'terminal/terminal/devicesn',
    method: 'GET',
    params: { agent_id }
  })
}

/**
 * 终端添加配置
 * @param {Object} date 添加参数
 */
export function TerminalConfigAdd(date) {
  const data = {
    category_id: date.category_id,
    device_name: date.device_name,
    desc: date.desc
  }
  return request({
    url: 'terminal/equipment/add_terminal',
    method: 'POST',
    data
  })
}

/**
 * 终端管理初试化
 * @param {Number} agent_id 代理商id
 */
export function TerminalAdminInit(agent_id) {
  return request({
    url: '/terminal/terminal/display',
    method: 'GET',
    params: { agent_id }
  })
}

/**
 * 终端管理分页
 * @param {Number} agent_id 代理商id
 * @param {Number} page 分页页码
 * @param {Object} date 搜索参数
 */
export function TerminalAdminPage(agent_id, date, page) {
  return request({
    url: '/terminal/terminal/display',
    method: 'GET',
    params: { agent_id, sn: date.sn, category: date.category, page }
  })
}

/**
 * 终端管理搜索
 * @param {Number} date 搜索参数
 * @param {Number} agent_id 代理商id
 */
export function TerminalAdminSearch(agent_id, date) {
  return request({
    url: '/terminal/terminal/display',
    method: 'GET',
    params: { agent_id, sn: date.sn, category: date.category }
  })
}

/**
 * 终端管理详情
 * @param {Number} depot_id 终端id
 */
export function TerminalAdminList(depot_id) {
  return request({
    url: '/terminal/terminal/see',
    method: 'GET',
    params: { depot_id }
  })
}

/**
 * 终端解除绑定
 * @param {Number} bind_id 终端id
 */
export function TerminalAdminFileBind(bind_id) {
  return request({
    url: '/terminal/terminal/relieve',
    method: 'PUT',
    params: { bind_id }
  })
}

/**
 * 终端管理删除终端
 * @param {Number} depot_id 终端id
 */
export function TerminalAdminDelete(depot_id) {
  return request({
    url: '/terminal/terminal/del',
    method: 'DELETE',
    params: { depot_id }
  })
}

/**
 * 终端管理添加终端入库
 * @param {Object} date 添加数据
 */
export function TerminalStorageAdd(date) {
  const data = {
    device_sn: date.sn,
    category: date.category_id,
    device_id: date.device_name
  }
  return request({
    url: '/terminal/terminal/warehousing',
    method: 'POST',
    data
  })
}

/**
 * 终端批量入库
 * @param {Number} agent_id 代理商id
 * @param {Number} file 文件路径
 */
export function terminalBatchStorage(agent_id, file) {
  const data = {
    agent_id,
    file
  }
  return request({
    url: '/terminal/terminal/batch_warehousing',
    method: 'POST',
    data
  })
}
